<template>
  <div class="card-items">
    <div class="head-part">
      <div class="title">
        <img src="@/assets/van-img.png" alt="" />
        <span>网络</span>
      </div>
    </div>

    <div class="content">
      <div
        :class="index == 0 ? 'item-box' : 'item-box1'"
        v-for="(item, index) in listData"
        :key="index"
      >
        <div class="top">
          <div
            class="title"
            :class="index == 0 ? 'title-white' : 'title-black'"
          >
            {{ item.title }}
          </div>
          <div
            class="line"
            :class="index == 0 ? 'line-gray' : 'line-yellow'"
          ></div>
        </div>
        <div class="value-box">
          <div
            class="value"
            :class="index == 0 ? 'value-white' : 'value-black'"
          >
            {{ item.value }}
          </div>
          <div class="hb">
            {{ "环比" }}
            <div :class="isNegative(item.hb) ? 'value-yellow' : 'value-green'">
              {{ item.hb }}
            </div>
            <img v-if="isNegative(item.hb)" src="@assets/pan-view/up(1).png" />
            <img v-else src="@assets/pan-view/up.png" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { Toast } from "vant";
import { reactive, toRefs, onMounted } from "vue";
export default {
  props: ["itemObj"],
  setup(props) {
    let item = props.itemObj;
    const state = reactive({
      listData: item,
    });

    //判断是否为负数
    function isNegative(num) {
      if (!num) return true;
      num = num + "";
      if (num.indexOf("-") != -1 && num != "-") return true;
      return false;
    }

    onMounted(() => {
      let listData = state.listData;
      if (listData.length <= 0) {
        Toast("无地市数据");
        return;
      }
    });
    return {
      ...toRefs(state),
      isNegative,
    };
  },
};
</script>
<style lang="scss" scoped>
.card-items {
  margin: 10px;
  width: calc(100% - 20px);
  background-color: #fff;
  border-radius: 5px;
  //   padding: 10px 0 2px 10px;
  margin-bottom: 10px;
  .head-part {
    padding-left: 10px;
    padding-top: 10px;
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    .qs-text {
      padding: 0 15px;
      line-height: 24px;
      color: #666666;
      margin-right: 10px;
      font-size: 12px;
      background: #ffffff;
      box-shadow: 0px 0px 2px 0px rgba(0, 0, 0, 0.2);
      border-radius: 4px;
    }
  }
  .title {
    width: 50%;
    display: flex;
    align-items: center;
    span {
      font-size: 16px;
      font-weight: 400;
      color: #333333;
    }
  }

  .content {
    display: flex;
    flex-wrap: wrap;
    // justify-content: space-around;
    background: #ffffff;
    width: 100%;
    padding-bottom: 10px;

    .item-box {
      margin-left: 10px;
      margin-top: 10px;
      width: 45%;
      height: 96px;
      background: url("@assets/pan-view/编组 12.png") no-repeat 0 0;
      background-size: 100% 100%;
    }

    .top {
      width: 100%;
      display: flex;

      .title {
        margin: 10px;
        width: 80%;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        line-height: 20px;
      }

      .title-white {
        color: #ffffff;
      }

      .title-black {
        color: #333333;
      }

      .line {
        margin: 10px;
        margin-top: 20px;
        width: 16px;
        height: 4px;
        border-radius: 2px;
      }

      .line-gray {
        background: rgba(255, 255, 255, 0.7);
        border: 0px solid #979797;
      }

      .line-yellow {
        background: #ff9900;
        border: 0px solid #979797;
      }
    }

    .value-box {
      display: flex;
      justify-content: space-around;
      align-items: center;

      .value {
        font-size: 22px;
        font-family: Helvetica-Bold, Helvetica;
        font-weight: bold;
        color: #333333;
        line-height: 24px;
      }

      .value-white {
        color: #ffffff;
      }

      .value-black {
        color: #333333;
      }
      .hb {
        display: flex;
        align-items: center;
        justify-content: space-around;
        width: 72px;
        height: 14px;
        background: #ffffff;
        font-size: 10px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #666666;
        line-height: 14px;

        .value-yellow {
          color: #e34343;
        }

        .value-green {
          color: #10cfa5;
        }

        img {
          height: 10px;
          width: 6px;
        }
      }
    }

    .item-box1 {
      margin-left: 10px;
      margin-top: 10px;
      width: 45%;
      height: 96px;
      background: url("@assets/pan-view/编组 11.png") no-repeat 0 0;
      background-size: 100% 100%;
    }
  }
}
</style>
